# encoding = utf-8

from application.logging import logger
from application.model.v3_model.CV_Parameter_online.get_best_params_ import get_best_params_
from application.utils.CodeTimingUtil import CodeTimingUtil


@CodeTimingUtil(name="[调参]CV_sub_sample")
def CV_sub_sample(train_x, train_y, n_estimators, max_depth, min_child_weight, gamma):
    #
    cv_params = {
        "subsample": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
        "colsample_bytree": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
    }
    #
    other_params = {
        "learning_rate": 0.05,
        "n_estimators": n_estimators,
        "max_depth": max_depth,
        "min_child_weight": min_child_weight,
        "seed": 0,
        "subsample": 1,
        "colsample_bytree": 0.6,
        "gamma": gamma,
        "reg_alpha": 0.03,
        "reg_lambda": 0.03
    }
    #
    logger.info(f"调参开始[subsample,colsample_bytree]: {'*' * 50}")
    best_params_ = get_best_params_(train_x=train_x, train_y=train_y, cv_params=cv_params, other_params=other_params)
    subsample = best_params_["subsample"]
    colsample_bytree = best_params_["colsample_bytree"]
    logger.info(f"调参结束[subsample,colsample_bytree]:[{subsample}, {n_estimators}] {'*' * 50}")
    return subsample, colsample_bytree

    pass


pass

if __name__ == "__main__":
    pass
